package cn.qinhao.pethome.login.controller;

import cn.qinhao.pethome.basic.exception.BusinessException;
import cn.qinhao.pethome.basic.until.AjaxResult;
import cn.qinhao.pethome.login.domain.LoginVo;
import cn.qinhao.pethome.login.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LogininfoController {
    @Autowired
    private ILogininfoService logininfoService;
   @PostMapping
   public AjaxResult login(@RequestBody LoginVo loginVo) {
       try {
           String login = logininfoService.login(loginVo);
           return AjaxResult.me().setSuccess(true).setResultObj(login);//返回token数据
       } catch (
               BusinessException e) {
           return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
       } catch (Exception e) {
           e.printStackTrace();
           return AjaxResult.me().setSuccess(false).setMessage("网络服务异常！！！");
       }

   }

}
